import { defineConfig, loadEnv } from "vite";
import path from "node:path";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import viteCompression from "vite-plugin-compression";
import UnoCSS from "unocss/vite";
export default defineConfig(({ mode, command }) => {
  if (command === "serve") {
    console.log("is serve");
  } else {
    console.log("is build");
  }
  //
  // console.log(process.cwd())
  const env = loadEnv(mode, process.cwd());
  return {
    base: "/",
    resolve: {
      alias: {
        "@": path.join(__dirname, "src"),
      },
    },
    server: {
      port: 8000,
      // 允许局域网访问vite服务
      host: "0.0.0.0",
      open: true,
      // proxy: {
      //   "/api": {
      //     target: "http://localhost:8080",
      //   },
      // },
    },
    build: {
      outDir: "dist",
    },
    plugins: [
      viteCompression(),
      vue(),
      AutoImport({
        // 自动导入配置开启eslintrc，避免变量未定义报错
        eslintrc: {
          enabled: true,
        },
        imports: ["vue", "vue-router"],
        dts: true,
      }),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(__dirname, "src/assets/icons")],
        symbolId: "icon-[name]",
      }),
    ],
    // 全局Scss变量
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "src/styles/define.scss";`,
        },
      },
    },
  };
});

//
